{% extends 'IcsocUIBundle::page.html.twig' %}
{% from 'IcsocUIBundle:Macro:actions.html.twig' import button %}

{% block stylesheet %}
    {{ parent() }}
    {% stylesheets
    '@gritter_css'
    filter='cssrewrite' filter='uglifycss'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
    <style>
        .all_width {
            width: 60%;
        }
    </style>
{% endblock %}

{% block content %}
    <h3 class="header smaller lighter green">挂机短信:</h3>

    <form class="form-horizontal form-group col-xs-12 col-sm-12" role="form" action="{{ path('icsoc_security_develop_update_hang_up_sms') }}" method="post">
        <div class="form-group col-xs-12 col-sm-12">
            <div class="col-xs-2 col-sm-2" style="text-align: right;">
                <strong>{{ 'Messages sent to the customer'|trans }}</strong>
            </div>
        </div>
        <div class="form-group col-xs-12 col-sm-12">
            <label for="firstname" class="col-xs-3 col-sm-3 control-label" style="text-align: right">启用接通推送</label>
            <div class="col-sm-9 col-xs-9">
                <div class="col-xs-12 col-sm-12">
                    <label class="radio-inline ">
                        <input class="is_connect" name="is_connect" required="required" value="0" aria-required="true" type="radio" {% if data.is_connect == 0 %}checked{% endif %}>    禁用
                    </label>
                    <label class="radio-inline ">
                        <input class="is_connect"  name="is_connect" required="required" value="1" aria-required="true" type="radio" {% if data.is_connect == 1 %}checked{% endif %}>    启用
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="firstname" class="col-xs-3 col-sm-3 control-label" style="text-align: right;">内容</label>
            <div class="col-sm-9 col-xs-9">
                <textarea class="form-control connect_sms all_width" name="connect_sms" rows="1">{{ data.connect_sms }}</textarea>
            </div>
        </div>
        <div class="form-group col-xs-12 col-sm-12" style="margin-top: 20px">
            <label for="firstname" class="col-xs-3 col-sm-3 control-label" style="text-align: right">启用未接通推送</label>
            <div class="col-sm-9 col-xs-9">
                <div class="col-xs-12 col-sm-12">
                    <label class="radio-inline " id="">
                        <input class="is_busy" name="is_busy" required="required" value="0" aria-required="true" type="radio" {% if data.is_busy == 0 %}checked{% endif %}>    禁用
                    </label>
                    <label class="radio-inline " id="">
                        <input class="is_busy" name="is_busy" required="required" value="1" aria-required="true" type="radio" {% if data.is_busy == 1 %}checked{% endif %}>    启用
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="firstname" class="col-xs-3 col-sm-3 control-label" style="text-align: right;">内容</label>
            <div class="col-sm-9 col-xs-9">
                <textarea class="form-control busy_sms all_width" name="busy_sms" rows="1">{{ data.busy_sms }}</textarea>
            </div>
        </div>

        <div class="form-group col-xs-12 col-sm-12">
            <div class="col-xs-2 col-sm-2" style="text-align: right;">
                <strong>{{ 'Messages sent to the agent'|trans }}</strong>
            </div>
        </div>
        <div class="form-group col-xs-12 col-sm-12">
            <label for="firstname" class="col-xs-3 col-sm-3 control-label" style="text-align: right">挂机短信</label>
            <div class="col-sm-9 col-xs-9">
                <select class="form-control input_left_none endsms_type all_width" name="endsms_type">
                    <option value="0">无</option>
                    <option value="1">未接发送</option>
                    <option value="2">接听发送</option>
                    <option value="3">全部发送</option>
                </select>
            </div>
        </div>
        <div class="form-group col-xs-12 col-sm-12">
            <label for="firstname" class="col-xs-3 col-sm-3 control-label" style="text-align: right">短信发送号码</label>
            <div class="col-sm-9 col-xs-9" id="endsms_phone">
                <input type="text" class="form-control endsms_phone all_width col-sm-6 col-xs-6" name="endsms_phone" value="{{ data.endsms_phone }}">
                <span class="help-button" data-rel="popover" data-trigger="hover" data-placement="bottom" data-content="为空则默认给当前静态坐席签入的手机号码发送，设置则发送到指定手机号码上。" title="" data-original-title="">?</span>
            </div>
        </div>

        <div class="form-group col-xs-12 col-sm-12" style="margin-top: 10px">
            <div class="col-xs-3 col-sm-3" style="text-align: center;">
                <strong>企业签名</strong>
            </div>
            <div class="col-sm-9 col-xs-9">
                <input type="text" class="form-control vcc_signature all_width" name="vcc_signature" value="{{ data.vcc_signature }}" placeholder="" maxlength="100">
            </div>
        </div>

        <div class="clearfix form-actions form-group col-xs-12 col-sm-12">
            <div class="col-md-offset-4 col-md-8">
                <button class="btn btn-info" type="submit" id="but_sub">
                    <i class="ace-icon fa fa-check bigger-110"></i>
                    提交
                </button>
                &nbsp; &nbsp; &nbsp;
                <button class="btn" type="reset">
                    <i class="ace-icon fa fa-undo bigger-110"></i>
                    重 置
                </button>
            </div>
        </div>
    </form>
{% endblock %}

{% block footer %}
    {% javascripts
    '@gritter_js'
    '@common_js'
    filter='uglifyjs'
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
    <script type="text/javascript">
        $(function () {
            $(".endsms_type option[value='{{ data.endsms_type }}']").attr('selected', 'selected');
            $('.endsms_phone').change(function(){
                isPhone();
            });
            $('form:first').submit(function(){
                if (!isConnect()) {
                    gritterAlert('{{ 'Prompt'|trans }}', '接通推送内容不能为空', 'error');
                    return false;
                }
                if (!isBusy()) {
                    gritterAlert('{{ 'Prompt'|trans }}', '未接推送内容不能为空', 'error');
                    return false;
                }
                if (!isPhone()) {
                    gritterAlert('{{ 'Prompt'|trans }}', '短信发送号码不正确', 'error');
                    return false;
                }
                var signature = $('.vcc_signature').val();
                if (signature.trim() == '') {
                    gritterAlert('{{ 'Prompt'|trans }}', '企业签名不能为空', 'error');
                    return false;
                }
            });
        });
        //判断手机号码
        function isPhone(){
            var phone = $(".endsms_phone").val();
            if (phone != '') {
                if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
                    $('#endsms_phone').addClass('has-error');
                    return false;
                }
            }
            $('#endsms_phone').removeClass('has-error');
            return true;
        }
        //判断接通推送内容
        function isConnect() {
            if ($('.is_connect:radio:checked').val() == 1) {
                 if ($('.connect_sms').val().trim() == '') {
                    return false;
                 }
            }
            return true;
        }

        //判断接通推送内容
        function isBusy() {
            if ($('.is_busy:radio:checked').val() == 1) {
                if ($('.busy_sms').val().trim() == '') {
                    return false;
                }
            }
            return true;
        }
    </script>
{% endblock %}